-- Prefan Access Controller
-- Usermessage Control

require( "glon" )

if SERVER then

	function PAC.UMStart( name, ply, ... )

		PAC.Print( PAC_CONSOLE, "Usermessage Parse " .. name .. " to " .. ply:Nick() .. " with " .. tostring( unpack( arg ) ) )
	
		umsg.Start( name, ply )
		
			umsg.Short( #arg )
		
			for I = 1, #arg do
				
				local tab = glon.encode( arg[I] )
				
				umsg.String( tab )
				
			end
			
		umsg.End()
		
	end
	
	concommand.Add( "_UMTEST", function( ply, _, args ) PAC.UMStart( "PAC_UMTest", ply, args[1], args[2], args[3] ) end )
	
end

if CLIENT then

	function PAC.UMHook( name, func )

		local function um( UMSG )
		
			local data = {}
		
			local num = UMSG:ReadShort()
			
			for I = 1, num do
			
				local tab = glon.decode( UMSG:ReadString() )
				
				table.insert( data, tab )
				
			end
			
			func( unpack( data ) )
			
		end
		usermessage.Hook( name, um )
		
	end
	
	PAC.UMHook( "PAC_UMTest", function( string1, string2, string3 ) print( string1, string2, string3 ) end )
	
end
